package com.bbt.dormassistant.controller;

import com.bbt.dormassistant.service.ManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "管理员接口")
@RequestMapping("/manager")
@RestController
public class ManagerController {


    @Autowired
    private ManageService manageService;


    @ApiOperation(value = "根据用户ID将用户升级为管理员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "String")
    })
    @PostMapping(value = "/authentication")
    public Map<String,Object> authentication(@RequestParam(value = "userId") String userId){
        Map<String,Object> map =  new HashMap<>();
        map.put("success",manageService.authentication(userId));
        return map;
    }


    @ApiOperation(value = "查询所有管理员")
    @GetMapping(value = "/queryAllManagers")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currIndex", value = "当前页码(可选项)", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页大小(可选项)", dataType = "int")
    })
    public Map<String,Object> queryAllManagers(@RequestParam(value = "currIndex",required = false) Integer currIndex,
                                               @RequestParam(value = "pageSize",required = false) Integer pageSize){
        Map<String,Object> map =  new HashMap<>();
        map.put("managers",manageService.queryAllManagers(currIndex,pageSize));
        return map;
    }



    @ApiOperation(value = "根据ID，批准记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "recordId", value = "预约记录ID",  dataType = "int"),
            @ApiImplicitParam(name = "userId", value = "管理员ID(只有管理员拥有该权限)", dataType = "String")
    })
    @PostMapping("/applyRecord")
    public Map applyRecord(@RequestParam(value = "recordId") Integer recordId,
                           @RequestParam(value = "userId") String userId){
        Map<String,Object> map = new HashMap<>();
        map.put("success",manageService.applyRecord(recordId,userId));
        return map;
    }


    @ApiOperation(value = "删除评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "评论ID", dataType = "int"),
            @ApiImplicitParam(name = "userId", value = "管理员ID(只有管理员拥有该权限)", dataType = "String")
    })
    @PostMapping("/removeComment")
    public Map removeComment(@RequestParam(value = "commentId") Integer commentId,
                           @RequestParam(value = "userId") String userId){
        Map<String,Object> map = new HashMap<>();
        map.put("success",manageService.removeCommentById(commentId,userId));
        return map;
    }


    @ApiOperation(value = "删除文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "messageId", value = "文章ID", dataType = "int"),
            @ApiImplicitParam(name = "userId", value = "管理员ID(只有管理员拥有该权限)", dataType = "String")
    })
    @PostMapping("/removeMessage")
    public Map removeMessage(@RequestParam(value = "messageId") Integer messageId,
                             @RequestParam(value = "userId") String userId){
        Map<String,Object> map = new HashMap<>();
        map.put("success",manageService.removeMessageById(messageId,userId));
        return map;
    }


}
